<template>
  <view class="login-container">
    <view class="login-lgoo">
      君合为道
    </view>
    <view class="login-form">
      <u-field
        v-model="mobile"
        label="账号"
        required
        placeholder="请填写账号"
      >
      </u-field>
      <u-field
        v-model="password"
        label="密码"
        required
        password
        placeholder="请填写密码"
      >
      </u-field>
      <view class="login-btns">
        <u-button type="primary" class="login-btn" @click="onLogin">登录</u-button>
      </view>
      
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        mobile: '',
        password: '',
      }
    },
    methods: {
      onLogin() {
        const data = {
          email: this.mobile,
          password: this.password
        }
        this.$http({
          url: '/doLogin',
          data
        }).then(res => {
          const { token } = res.data
          uni.setStorageSync('Token', token)
          this.$store.commit('setToken', token)
          wx.reLaunch({
            url: '../index/index'
          })
        }).catch(err => {
          wx.showToast({
            icon: 'none',
            title: err.msg || '登录失败'
          })
        })
      }
    }
  }
</script>

<style lang="less">
  .login-container{
    .login-lgoo{
      font-size: 34rpx;
      text-align: center;
      font-weight: bold;
      padding: 100rpx 50rpx;
    }
    .login-form{
      padding: 0 30rpx;
    }
    .login-btns{
      padding-top: 30rpx;
    }
    .login-btn{
      margin-top: 30rpx;
    }
  }
</style>
